package org.leetcode.middle.leetcode74;

public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {

        int m = matrix.length;
        int n = matrix[0].length;

        int [] nums = new int[m*n];

        int index =0;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                nums[index]=matrix[i][j];
                index++;
            }
        }

        int left = 0;
        int right =m*n-1;

        while (left<=right){
            int mid = (left+right)/2;
            int num =nums[mid];

            if (num==target) {
                return true;
            }else if (num<target) {
                left=mid+1;
            }else if (num>target) {
                right=mid-1;
            }
        }

        return false;
    }
}
